package com.jk.admin.service;

import com.jk.admin.dao.ProductDao;
import com.jk.admin.entity.Product;
import com.jk.admin.entity.Shoptype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class ProductService {
    @Autowired
    private ProductDao productDao;
    @Autowired
    RedisTemplate redisTemplate;


    public List<Product> getListPro(Product product) {
      /*  Gson gson = new Gson();
        //定义key
        String   cacheKey = "Product";

        Boolean hasKey = redisTemplate.hasKey(cacheKey);

        if(hasKey){
         String sir = (String) redisTemplate.opsForValue().get(cacheKey);
            List<Product> listPro = new ArrayList<>();
            listPro = gson.fromJson(sir, new TypeToken<List<Product>>() {
            }.getType());
            return listPro;
        }else {*/
            List<Product> listPro = productDao.getListPro(product);
       //     redisTemplate.opsForValue().set(cacheKey,gson.toJson(listPro));
            return listPro;
      //  }



    }

    public void delPro(Integer id) {
        productDao.delPro(id);
    }

    public void addPro(Product product) {



        productDao.addPro(product);
    }

    public void updPro(Product product) {
        productDao.updPro(product);
        //redisTemplate.delete("Product");

    }

    public Product huiPro(Integer id) {
        return productDao.huiPro(id);
    }

    public HashMap<String,Product> getecharts() {
       return productDao.getecharts();
    }


    public List<Product> getListPros() {
        return productDao.getListPros();
    }

    public void addType(Shoptype shoptype) {

        productDao.addType(shoptype);
    }
}


